package com.iflysse.controller;

import java.util.List;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.iflysse.dto.TeachingClassDto;
import com.iflysse.dto.TeachingClassUpdateDto;
import com.iflysse.service.TeachingClassService;
import com.iflysse.vo.AjaxResult;
import com.iflysse.vo.TeachingClassDetailVo;
import com.iflysse.vo.TeachingClassVo;

@RequestMapping("/teacherClass")
@RestController
public class TeachingClassController {
	
	@Autowired
	private TeachingClassService teacherClassService;
	
	@PostMapping("/queryAllClass")
	public AjaxResult teacherClass(String userId) {
		List<TeachingClassVo> map = teacherClassService.findTeacherClass(userId);
		return AjaxResult.success(map);
		
	}
	
	@PostMapping("/addTeacherClass")
	public AjaxResult addTeacherClass(@Valid TeachingClassDto form) {
		int success = teacherClassService.addTeacherClass(form);
		return AjaxResult.getResultBySuccess(success);
	}
	
	@PostMapping("/deleteTeacherClass")
	public AjaxResult deleteTeacherClass(String userId,String classId) {
		int success = teacherClassService.deleteTeacherClass(userId,classId);
		return AjaxResult.getResultBySuccess(success);
	}
	
	@PostMapping("/updateClassInfo")
	public AjaxResult updateTeacherClass(@Valid TeachingClassUpdateDto form) {
		int success = teacherClassService.updateTeacherClass(form);
		return AjaxResult.getResultBySuccess(success);
	}
	
	@PostMapping("/queryClassInfo")
    public AjaxResult queryClassInfo(String teachingClassId){
		TeachingClassDetailVo vo = teacherClassService.queryClassInfoById(teachingClassId);
		
		return AjaxResult.success(vo);
    }

}
